package com.shixun;

import java.util.*;


public class Ktv {
     private ArrayList<Data>data = new ArrayList<>();
     Scanner sc =new Scanner(System.in);
    private Data logd;


    //
    public void  staty (){
     while (true) {
            System.out.println("=====欢迎进入KTV点歌系统====");
            System.out.println("1.用户登录");
            System.out.println("2.用户注册");
            System.out.println("请选择：");
            int num = sc.nextInt();
            switch (num){
                case 1 -> log();
                case 2 -> enroll();
            }
        }
    }
    //登录
     private  void  log (){
         System.out.println("==用户登录==");
        if (data.size() == 0){
            return;
        }
         System.out.println("请输入用户名：");
         String Username = sc.next();
         if(Username != null){
             while (true) {
                 System.out.println("请输入密码： ");
                 String Password = sc.next();
                 Data  id= data.get(0);
                 if(Password.equals(id.getPassword())){
                     logd= id;
                     System.out.println("登陆成功"+id.getUsername());


                     show();
                     return;
                 }else {
                     System.out.println("密码错误！！！");
                 }
             }
         }else {
             System.out.println("出错了！！！");
         }


     }
    //注册
    private  void enroll(){
        System.out.println("==用户注册==");
        Data d= new Data();

        System.out.println("请输入用户名：");
        String ursename = sc.next();
        d.setUsername(ursename);

        while (true) {
            System.out.println("请输入密码： ");
            String password = sc.next();
            System.out.println("请再次输入密码（与上一行相同）：  ");
            String okpassword = sc.next();
            if(okpassword.equals(password)){
                d.setPassword(okpassword);
                d.getPassword();
                break;
            }else {
                System.out.println("两次密码不一致！！！");
            }
        }
        data.add(d);
        System.out.println(d.getUsername()+"注册成功");
    }

  private  void show(){
      while (true) {
          System.out.println(logd.getUsername()+"可选如下功能进行操作");
          System.out.println("1.添加歌曲");
          System.out.println("2.歌曲置顶");
          System.out.println("3.所选歌曲提前一位");
          System.out.println("4.退出");
          System.out.println("5.查看歌曲列表");
          System.out.println("6.删除歌曲信息");
          int se = sc.nextInt();
          switch (se){
              case 1: musicadd();break;
              case 2: settop();break;
              case 3: musictop();break;
              case 4:
                  System.out.println("期待下次的见面，再见！！！");
                  return;
              case 5: musicf();break;
              case 6:muiscrevom(); break;
          }
      }
  }

    List l =new ArrayList();
    private void muiscrevom() {
        System.out.println("请输入需要删除的歌曲信息");
        String muiscrevomname = sc.next();
        int index = l.indexOf(muiscrevomname);
        if(index <0 && index >10){
            System.out.println("曲目不存在");
        }else{
            l.remove(index);
            System.out.println("已删该曲目"+muiscrevomname);
            System.out.println(l);
        }
    }
    private void musicf() {
        System.out.println(l);
    }
    private void musictop() {
        //提前一位
        System.out.println("请输入想要上移曲目的名字");
        String nmae=sc.next();
        int index = l.indexOf(nmae);
        if(index < 0 ){
            System.out.println("曲目不存在");
        }else if(index == 0 ){
            System.out.println("曲目已在顶部无法在上移");
        }else {
            System.out.println("请输入下标");
            l.add(sc.nextInt()-1,nmae);
            l.remove(index+1);
            System.out.println(l);
        }
    }
    private void settop() {
        //置顶
        System.out.println("请输入想要置顶曲目的名字");
        String misicname = sc.next();
        int index= l.indexOf(misicname);
        if(index < 0){
            //
            System.out.println("曲目不存在");
        }else {
            l.remove(index);
            l.add(0,misicname);
            System.out.println("以置顶该曲目"+misicname);
            System.out.println("当前歌曲列表 "+ l);
        }
    }
    private void musicadd() {
        System.out.println("当前曲目为："+l.get(0));
        for (int i= 1 ; i<=10; i++){
            l.add(sc.next());
        }
        System.out.println(l);
    }


}
